package com.hyz.login.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyz.login.model.Hospitalprice;
import com.hyz.login.model.Outpatienttype;
import com.hyz.login.model.Pharmacy;
import com.hyz.login.service.HospitalpriceService;
import com.hyz.login.service.OutpatienttypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.ArrayList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zwq
 * @since 2022-11-23
 */
@Controller
public class OutpatienttypeController {

    Logger logger = LoggerFactory.getLogger(OutpatienttypeController.class);

    @Autowired
    private OutpatienttypeService outpatienttypeService;
    @Autowired
    private HospitalpriceService hospitalpriceService;

    @RequestMapping("/page/caoout/selout")
    @ResponseBody
    public Object selout(@RequestParam(required = false) String projectName,
                         @RequestParam(required = false,defaultValue = "1")Integer page,
                         @RequestParam(required = false,defaultValue = "5")Integer limit){
        IPage iPage = outpatienttypeService.findByLikeNamePage(projectName, page, limit);
        return "{\"msg\":\"\",\"code\":0,\"count\":"+iPage.getTotal()+",\"data\":"+ JSON.toJSONString(iPage.getRecords())+"}";
    }

    @GetMapping("/inout/selAll")
    @ResponseBody
    public String selAll(@RequestParam(required = false,defaultValue = "")String pharmacyName,
                         @RequestParam(required = false,defaultValue = "1")Integer page,
                         @RequestParam(required = false,defaultValue = "7")Integer limit){
        IPage<Outpatienttype> iPage = outpatienttypeService.findByLikeNamePage(pharmacyName, page, limit);
        return "{\"msg\":\"\",\"code\":0,\"count\":"+iPage.getTotal()+",\"data\":"+ JSON.toJSONString(iPage.getRecords())+"}";
    }

    @PostMapping("/hos/add")
    @ResponseBody
    public String add(Integer registerid,Hospitalprice hospitalprice,Integer type){
        hospitalprice.setRegisterId(registerid);
        hospitalprice.setState(type);
        hospitalprice.setRepicetotal(hospitalprice.getRepiceprice());
        int ret = hospitalpriceService.addDrug(hospitalprice);
        if (ret>0){
            return "添加成功";
        }
        return "添加失败";
    }
}

